package com.shs;

import com.shs.main.Stack;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Scanner;

import static com.shs.main.Calculator.*;
import static com.shs.main.Calculator.Calculate;

/**
 * @Author 晚点再动心
 * @Date 2022/9/17
 */
public class MainClass {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Stack stack = new Stack();
        boolean temp = true;
        while (temp){
            System.out.println("+-----------------+");
            System.out.println("||     计算器     ||");
            System.out.println("||  1.清零       ||");
            System.out.println("||  2.混合运算    ||");
            System.out.println("||  3.退出       ||");
            System.out.println("+----------------+");
            System.out.print("请输入选项：");

            //输入选项
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    //清空栈
                    stack.clean();
                    System.out.println("===清零====");
                    break;
                case 2:
                    System.out.println("====混合运算===");
                    System.out.println("请输入需要计算的表达式：");
                    String expression = scanner.next();
                    // 对用户的输入做处理
                    expression = replaceStr(expression);

                    // 将用户输入的表达式转换为集合
                    List<String> centerList = stringTolist(expression);

                    // 中缀表达式转换为后缀表达式
                    List<String> endList= centerToEnd(centerList);

                    // 计算结果
                    String result = Calculate(endList);

                    double doubleResult = Double.parseDouble(result);
                    DecimalFormat doubleFormat=new DecimalFormat("0.00");
                    String results = doubleFormat.format(doubleResult);
                    System.out.println("您的计算结果为："+"\n" + results);
                    stack.clean();
                    break;
                case 3:
                    System.out.println("====退出=====");
                    temp = false;
                    break;

                default:
                    System.out.println("输入有误");
            }
        }
    }
}
